<!-- src/components/ProductCard.vue -->
<template>
  <div class="product-card" @click="viewDetails">
    <div class="product-image">
      <img :src="product.image" :alt="product.name" />
      <div class="product-type">{{ product.type }}</div>
    </div>

    <div class="product-info">
      <h3 class="product-name">{{ product.name }}</h3>
      <p class="product-origin">{{ product.origin }} • {{ product.alcohol }}度</p>
      <p class="product-description">{{ product.description }}</p>

      <div class="product-footer">
        <div class="product-price">
          <span class="price">¥{{ product.price }}</span>
        </div>
        <div class="product-actions">
          <button class="btn btn-primary" @click.stop="addToCart">加入购物车</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  product: {
    type: Object,
    required: true
  }
})

const emit = defineEmits(['view-details', 'add-to-cart'])

const viewDetails = () => {
  emit('view-details', props.product)
}

const addToCart = () => {
  emit('add-to-cart', props.product)
  // alert(`${props.product.name} 已加入购物车！`)
}
</script>

<style scoped>
.product-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: all 0.3s ease;
  cursor: pointer;
  height: 100%;
  width: 300px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
}

.product-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.product-image {
  position: relative;
  height: 250px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-image img {
  width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: cover;
}

.product-card:hover .product-image img {
  transform: scale(1.05);
}

.product-type {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(139, 69, 19, 0.9);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
}

.product-info {
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.product-name {
  font-size: 1.3rem;
  font-weight: bold;
  color: #2c3e50;
  margin-bottom: 8px;
  line-height: 1.4;
}

.product-origin {
  color: #7f8c8d;
  font-size: 0.9rem;
  margin-bottom: 10px;
  font-weight: 500;
}

.product-description {
  color: #555;
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 15px;
  flex: 1;
}

.product-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  margin-top: auto;
}

.product-price {
  display: flex;
  align-items: center;
}

.price {
  font-size: 1.5rem;
  font-weight: bold;
  color: #e74c3c;
}

.product-actions {
  display: flex;
  gap: 10px;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s;
}

.btn-primary {
  background-color: #8b4513;
  color: white;
}

.btn-primary:hover {
  background-color: #a0522d;
  transform: translateY(-1px);
}

@media (max-width: 768px) {
  .product-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .product-actions {
    width: 100%;
  }

  .btn {
    width: 100%;
  }
}
</style>
